"""
=================================================
@Author: Zenon
@Date: 2025-05-21
@Description：检测历史界面模块
==================================================
"""
from PySide6.QtGui import QFont
from PySide6.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout, QPushButton,
                               QTableWidget, QHeaderView, QAbstractItemView)


class HistoryPage(QWidget):
    """检测历史界面类"""
    def __init__(self, parent=None):
        super().__init__(parent)
        self.parent = parent
        self.font = parent.font if parent else QFont("Arial", 12)
        self.init_ui()
        
    def init_ui(self):
        """初始化UI"""
        layout = QVBoxLayout(self)
        layout.setContentsMargins(15, 15, 15, 15)
        layout.setSpacing(15)

        # 操作按钮区域
        btn_layout = QHBoxLayout()
        btn_layout.setSpacing(10)

        self.delete_history_button = QPushButton("删除选中记录")
        self.clear_history_button = QPushButton("清空所有记录")

        self.delete_history_button.setStyleSheet("background-color: #F44336; color: white;")
        self.clear_history_button.setStyleSheet("background-color: #FF9800; color: white;")

        self.delete_history_button.setFont(self.font)
        self.clear_history_button.setFont(self.font)

        btn_layout.addWidget(self.delete_history_button)
        btn_layout.addWidget(self.clear_history_button)

        # 历史记录表格
        self.history_table = QTableWidget()
        self.history_table.setColumnCount(6)
        self.history_table.setHorizontalHeaderLabels(["选择", "序号", "模型", "完成时间", "备注", "操作"])
        self.history_table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
        self.history_table.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeToContents)
        self.history_table.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.history_table.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.history_table.setFont(self.font)

        layout.addLayout(btn_layout)
        layout.addWidget(self.history_table)